package kudu;

import org.apache.kudu.client.*;

public class InsertDemo {
    public static void main(String[] args) {
        //1、获取客户端
        String masterAddr="linux122";
        KuduClient.KuduClientBuilder kuduClientBuilder = new KuduClient.KuduClientBuilder(masterAddr);
        kuduClientBuilder.defaultSocketReadTimeoutMs(5000);
        KuduClient client = kuduClientBuilder.build();


        try {
            //2、打开一张表
            KuduTable studentTable = client.openTable("student");
            //3、创建会话
            KuduSession kuduSession = client.newSession();
            //4、设置刷新模式
            kuduSession.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);
            //5、获取插入实例
            Insert insert = studentTable.newInsert();
            //6、声明带插入数据
            insert.getRow().addInt("id",1);
            insert.getRow().addString("name","Shibuya");
            //7、刷入数据
            kuduSession.flush();
            //8、应用插入实例
            kuduSession.apply(insert);
            //9、关闭会话
            kuduSession.close();
        } catch (KuduException e) {
            e.printStackTrace();
        } finally {
            try {
                client.close();
            } catch (KuduException e) {
                e.printStackTrace();
            }
        }


    }
}
